import { createRouter, createWebHashHistory } from 'vue-router';
const Layout = () => import('@/views/Layout');
const Home = () => import('@/views/home/index');
const TopCategory = () => import('@/views/category/index');
const SubCategory = () => import('@/views/category/sub');

const routes = [
	// 一级路由布局容器
	{
		path: '/',
		component: Layout,
        children: [
            { path: '/', component: Home },
            { path: '/category/:id', component: TopCategory },
            { path: '/category/sub/:id', component: SubCategory }
        ]
	}
];

const router = createRouter({
	history: createWebHashHistory(),
    routes,
    scrollBehavior(to, from, savedPosition) {
        // 始终滚动到顶部
        return { top: 0 }
      },
});

export default router;
